<?php
class Data_SplFileInfoSet implements Iterator
{
    /**
     * files and directories
     * 
     * @var array
     */
    protected $_rows = array();
    
    /**
     * Iterator pointer.
     */
    protected $_pointer = 0;
    
    /**
     * How many data rows there are.
     */
    protected $_count;

    /**
     * Constructor.
     */
    public function __construct($config = array())
    {
        // set the count of rows
        $this->_count = 0;
    }
    
    /**
     * Rewind the Iterator to the first element.
     * Similar to the reset() function for arrays in PHP.
     * 
     * @return void
     */
    public function rewind()
    {
        $this->_pointer = 0;
    }

    /**
     * Return the current element.
     * Similar to the current() function for arrays in PHP
     * 
     * @return mixed current element from the collection
     */
    public function current()
    {
        // is the pointer at a valid position?
        if (! $this->valid()) {
            return false;
        }
        
        // return the row object
        return $this->_rows[$this->_pointer];
    }

    /**
     * Return the identifying key of the current element.
     * Similar to the key() function for arrays in PHP.
     * 
     * @return int
     */
    public function key()
    {
        return $this->_pointer;
    }

    /**
     * Move forward to next element.
     * Similar to the next() function for arrays in PHP.
     * 
     * @return int The next pointer value.
     */
    public function next()
    {
        return ++$this->_pointer;
    }

    /**
     * Check if there is a current element after calls to rewind() or next().
     * Used to check if we've iterated to the end of the collection.
     * 
     * @return bool False if there's nothing more to iterate over
     */
    public function valid()
    {
        return $this->_pointer < $this->count();
    }

    /**
     * Returns the number of elements in the collection.
     * 
     * @return int
     */
    public function count()
    {
        return $this->_count;
    }

    /**
     * Returns true if $this->count > 0, false otherwise.
     * 
     * @return bool
     */
    public function exists()
    {
        return $this->_count > 0;
    }
    
    /**
     * Returns all data as an array.
     * 
     * Updates the $_data property with current row object values.
     * 
     * @return array
     */
    public function toArray()
    {
        return $this->_rows;
    }	
    
	/**
	 * Ajoute un élément à l'ensemble
	 *
	 * @param Data_Fsitem $item
	 */
	public function add($item)
	{
		$this->_rows[] = $item;
		++$this->_count;
		return $this;
	}
}
?>